from jili.calc import calcor_base
from talib import abstract as taabstract
class KDJ(calcor_base):
    def __init__(self,ta_arg={}):
        self.out = ["K", "D", "J"]
        self.input = ["high","low","close"]
        self.parameters = {"timeperiod":9,"m1":3,"m2":3}
        super().__init__(ta_arg)
        self.ta=taabstract.Function("STOCH")
        self.ta.set_input_names({"prices":self.input})
        self.ta.set_parameters({"fastk_period": self.parameters["timeperiod"], "slowk_period": self.parameters["m1"], "slowk_matype": 0, "slowd_period": self.parameters["m2"], "slowd_matype": 0})
        self.lookback = self.batch - 1
    # def 
    def calc(self):
        # super().onbar(bar)
        h_name=self.input[0]
        self.ta.set_input_arrays(self.hisbars)
        k=self.ta.outputs[0][-1]
        d=self.ta.outputs[1][-1]
        j=3*k-2*d
        return [k, d,j]
